<template>
  <div class="preview-container">

    <div class="album-content" v-if="albumDetail">
      <el-image :src="albumDetail.imgUrl" class="album-cover"></el-image>
      <div class="album-info">
        <el-text class="nickname">作者：{{ albumDetail.nickname }}</el-text>
        <el-text class="description">详情：{{ albumDetail.description }}</el-text>
        <el-text class="score">评分：{{ albumDetail.score }}</el-text>
      </div>
    </div>

    <div class="picture-list" v-if="albumDetail.pictureList && albumDetail.pictureList.length">
      <el-text class="list-title">壁纸列表</el-text>
      <div
        class="picture-item"
        v-for="(pic, index) in albumDetail.pictureList"
        :key="index"
        @click="goPreview(pic.id)"
      >
        <el-image :src="pic.smallPicurl" class="picture-image"></el-image>
        <el-text class="picture-classname">{{ pic.className }}</el-text>
        <el-text class="picture-description">{{ pic.description }}</el-text>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { getAlbum } from '@/api/wallpaper/album.js'

const albumDetail = ref({})
const router = useRouter()

// 保持数据获取逻辑不变
onMounted(async () => {
  try {
    const res = await getAlbum(router.currentRoute.value.params.id)
    if (res.code === 200) {
      albumDetail.value = res.data
    } else {
      ElMessage.error('获取专辑详情失败: ' + res.msg)
    }
  } catch (error) {
    ElMessage.error('请求错误: ' + error)
  }
})

const goPreview = (id) => {
  router.push({ path: `/preview/wallpaper/${id}` })
}

</script>

<style lang="scss" scoped>
.preview-container {
  display: flex;
  justify-content: space-between;
  padding: 20px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  height: 500px;
}

.album-content {
  flex: 1;
  max-width: 40%;
  display: flex;
  align-items: center;
  margin-right: 20px;
  padding: 15px;
  background-color: #fff;
  transition: transform 0.3s, box-shadow 0.3s;

  &:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }

  .album-cover {
    width: 150px;
    height: 150px;
    border-radius: 8px;
    margin-right: 20px;
    object-fit: cover;
    transition: transform 0.3s;

    &:hover {
      transform: rotate(5deg);
    }
  }

  .album-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;

    .nickname {
      font-size: 22px;
      color: #333;
      font-weight: bold;
      margin-bottom: 10px;
    }

    .description {
      font-size: 18px;
      color: #555;
      line-height: 1.6;
      margin-bottom: 10px;
    }

    .score {
      font-size: 16px;
      color: #999;
    }
  }
}

.picture-list {
  flex: 2;
  max-width: 55%;
  margin-top: 20px;

  .list-title {
    font-size: 22px;
    font-weight: bold;
    margin-bottom: 15px;
    color: #444;
  }

  .picture-item {
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    padding: 12px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
    transition: background-color 0.3s, transform 0.3s;

    &:hover {
      background-color: #f1f1f1;
      transform: translateY(-3px);
    }

    .picture-image {
      width: 70px;
      height: 70px;
      border-radius: 8px;
      margin-right: 12px;
      object-fit: cover;
    }

    .picture-classname {
      font-size: 18px;
      color: #333;
      font-weight: bold;
    }

    .picture-description {
      font-size: 15px;
      color: #777;
    }
  }
}
</style>
